package com.wzx.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.wzx.domain.company.Company;
import com.wzx.service.company.ICompanyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ApplyController {
    private Logger l = LoggerFactory.getLogger(this.getClass());
    @RequestMapping(path="index.do" ,method = {RequestMethod.GET,RequestMethod.POST})
    public String index(){
        return "index";
    }
    @RequestMapping(path="commit.do" ,method = {RequestMethod.GET,RequestMethod.POST})
    public String commit(){
        return "commit";
    }
    @RequestMapping(path="toApply.do" ,method = {RequestMethod.GET,RequestMethod.POST})
    public String toApply(){
        return "apply";
    }

    // Serialized class com.wzx.domain.company.Company must implement java.io.Serializable
    //因为rpc底层将对象序列化成二进制数据写到另一个服务器上。
    //在java需要对类实现序列化接口 Serializable
    @Reference //通过rpc查找 provider中的实现类对象
    ICompanyService iCompanyService;
    @RequestMapping(path="apply.do" ,method = {RequestMethod.GET,RequestMethod.POST})
    public @ResponseBody
    String apply(Company company){
        //调用service进行保存
        l.info("apply company "+company);

        try {
            iCompanyService.saveCompany(company);//表示成功
            return "1";
        } catch (Exception e) {//表示失败
            e.printStackTrace();
            return "-1";
        }

    }
}
